package com.pucong.gitee.database.backup.database.service;

import com.pucong.gitee.database.backup.database.util.BackupService;
import com.pucong.gitee.database.backup.database.vo.DeleteDataSchema;
import com.pucong.gitee.database.backup.database.vo.RenameDataSchema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class OperationDataSchemaServiceImpl implements OperationDataSchemaService {

    @Autowired
    private DatabaseStaticService databaseStaticService;

    @Override
    public List<String> getSchemaList(String databaseId, String databaseName) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String sessionId = request.getSession().getId();

        BackupService backupService = databaseStaticService.getConnectionById(sessionId, databaseId);
        List<String> schemaList = backupService.getSchemaList(databaseName);
        backupService.closeAll();
        return schemaList;
    }

    @Override
    public Boolean renameDataSchema(String databaseId, RenameDataSchema renameDataSchema) {
        return null;
    }

    @Override
    public Boolean deleteDataSchema(String databaseId, DeleteDataSchema deleteDataSchema) {
        return null;
    }
}
